<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AsyncController
 *
 * @author root
 */
include_once 'CommonController.php';
class AsyncController extends CommonController {
    
    public function preDispatch() {
        $this->session = new Zend_Session_Namespace('default');
        
        if(! $this->session->view){
            $this->session->view = $this->view;
            echo "ppppp";
        }
    }

    public function init(){
        //$this->_helper->viewRenderer->setNoRender();
        //$this->getHelper('layout')->disableLayout();
    }
    
    public function indexAction(){
        
    }

    
    public function getitemsAction(){
        echo json_encode($this->generatItems());
        $this->_helper->viewRenderer->setNoRender();
        $this->getHelper('layout')->disableLayout();
    }

    public function getitemByidAction(){
        $id = $this->getRequest()->getParam("itemId");
        $items = $this->generatItems();
        echo json_encode($items[$id]);
        $this->_helper->viewRenderer->setNoRender();
        $this->getHelper('layout')->disableLayout();
    }

        private function generatItems(){
        
        $items = array();
        
        for($i = 0; $i < 5; $i++ ){
            $newItem = new App_ItemDto();
            $newItem->name = md5(uniqid());
            $newItem->description = "some description";
            $newItem->id = $i;
            
            $items[] = $newItem;
        }
        
        return $items;
    }
    
    public function homeAction(){
        
    }

    public function getnoticeAction(){
        echo $this->session->view->notice("hello");
        $this->_helper->viewRenderer->setNoRender();
        $this->getHelper('layout')->disableLayout();

    }
    
    
}

